package com.example.jinzproduct.server.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.commons.entity.EvaluationDO;
import com.example.commons.entity.ExaminationResultsDO;
import com.example.jinzproduct.dao.EvaluationDao;
import com.example.jinzproduct.server.EvaluationService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;


/**
 * 
 * <pre>
 * 
 * </pre>
 * <small> 2021-10-20 14:11:17 | lance</small>
 */
@Service
public class EvaluationServiceImpl extends ServiceImpl<EvaluationDao, EvaluationDO> implements EvaluationService {


    @Override
    public EvaluationDO findOneByKv(Object... params) {
        return getOne(this.convertToEntityWrapper(params));
    }

    public QueryWrapper<EvaluationDO> convertToEntityWrapper(Object... params) {
        QueryWrapper<EvaluationDO> ew = new QueryWrapper<>();
        if (params == null) {
            return ew;
        }
        for (int i = 0; i < params.length; i++) {
            if (i % 2 == 1 && params[i] != null && StringUtils.isNotBlank(params[i].toString())) {
                if(String.valueOf(params[i - 1]).equals("name")){
                    ew.like((String) params[i - 1], params[i].toString());
                }else if(String.valueOf(params[i - 1]).equals("file_name")){
                    ew.like((String) params[i - 1], params[i].toString());
                }else if(String.valueOf(params[i - 1]).equals("title")){
                    ew.like((String) params[i - 1], params[i].toString());
                }else if(String.valueOf(params[i - 1]).equals("introduce")){
                    ew.like((String) params[i - 1], params[i].toString());
                }else{
                    ew.eq((String) params[i - 1], params[i].toString());
                }
            }
        }
        return ew;
    }
}
